// http://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int add(int, int);
char* add_str(char *, char* );

void main(){
	int (*fun)(int,int);
	fun = &add;
	int c = fun(1,2);
	printf("%d\n",c);

	char *(* fun2)(char*, char*);
	fun2 = add_str; // fun2=&add_str also ok
	char * result = fun2("hello,", "world");
	printf("%s\n", result);
	free(result);
}

int add(int a,int b){
	return a+b;
}

char * add_str(char* a, char* b){
	//http://stackoverflow.com/questions/308695/how-to-concatenate-const-literal-strings-in-c
	int len = strlen(a)+1;
	len += (strlen(b)+1);
	char* str =(char*) malloc(len);

	snprintf(str,len,"%s%s",a,b);
	return str;
}